#ifndef DEVICEWORKER_H
#define DEVICEWORKER_H

#include <QObject>
#include <QVariantMap>
#include "types.h"
#include "enums.h"

class CopperParticleDevice;

class DeviceWorker : public QObject
{
    Q_OBJECT

public:
    explicit DeviceWorker(QObject *parent = nullptr);
    ~DeviceWorker();

    void init();
    void cleanup();

public slots:
    // 网络连接管理
    void connectToDevice(const QString &host, quint16 port);
    void disconnectFromDevice();
    bool isConnected() const;
    void sendDeviceCommand(DeviceProtocol::IPCCommand command, const QVariantMap &params = QVariantMap());

signals:
    void connected();
    void disconnected();
    void errorOccurred(const QString &error);
    void processParametersReceived(ProcessParams params);
    void commandResponseReceived(DeviceProtocol::IPCCommand command,
                                 bool success, const QString &message);
    void commandDataResponseReceived(DeviceProtocol::IPCCommand command,
                                     bool success, const QVariantMap &params);
    void queryDataImmediatelyReceived(DeviceProtocol::IPCCommand command,
                                      const QVariantMap &data); // 立即查询数据信号
    void initialized();

private slots:
    void onCommandCompleted(DeviceProtocol::IPCCommand command, bool success, const QVariantMap &responseData);
    void onQueryDataReceived(DeviceProtocol::IPCCommand command, const QVariantMap &data); // 处理查询数据
private:
    CopperParticleDevice *m_device;
};

#endif // DEVICEWORKER_H
